export default () => {
    const downloadUrl = ref('')

    const checkVersion = async () => {
        const {appId, appVersionCode, osName, appVersion } = uni.getSystemInfoSync()
        const { data, code } = await g_api.client.apiCheckVersion({
            platformType: osName,
            versionCode: appVersionCode,
            version: appVersion,
            appCode: appId
        })
        if (code !== 200) {
            return false
        }

        downloadUrl.value = data.downloadUrl
        return data
    }

    const donwLoadVersion = async () => {
        // #ifdef APP-PLUS
        const { data, code } = await g_api.common.apiDownLoad({
            path: downloadUrl.value,
        })
        if (code == 200) {
            plus.runtime.openURL(data)
            return true
        }
         // #endif
        
    }

    return {
        checkVersion,
        donwLoadVersion
    }
}